from django.db import models
from datetime import datetime
from myappa.models import *
# Create your models here.


# 流程表7
class FlowModel(models.Model):
    fname = models.CharField(max_length=100,default='',verbose_name='流程名称')
    s_time = models.CharField(max_length=100,default=datetime.now,verbose_name='创建时间')
    status = models.IntegerField(default=0,verbose_name='0 没有生效 1 生效')

    class Meta:
        db_table = 'tb_flow'
    def __str__(self):
        return self.fname


# 流程节点表 8
class FlowNodeModel(models.Model):
    fn_name = models.CharField(max_length=100,default='',verbose_name='流程节点名称')
    flow = models.ForeignKey(FlowModel,on_delete=models.CASCADE,verbose_name='所属流程')

    class Meta:
        db_table = 'tb_flownode'
    def __str__(self):
        return self.fn_name


# 节点属性样式表 9
class NodeAttrTypeModel(models.Model):
    nat_name = models.CharField(max_length=100,default='',verbose_name='样式名称')

    class Meta:
        db_table = 'tb_natype'
    def __str__(self):
        return self.nat_name


# 节点属性表 10
class NodeAttrModel(models.Model):
    na_name = models.CharField(max_length=100,default='',verbose_name='节点属性名称')
    fnode = models.ForeignKey(FlowNodeModel,on_delete=models.CASCADE,verbose_name='流程节点表外键(所属流程节点)')
    natype = models.ForeignKey(NodeAttrTypeModel,on_delete=models.CASCADE,verbose_name='节点属性样式表外键(所拥样式)')

    class Meta:
        db_table = 'tb_nattr'
    def __str__(self):
        return self.na_name


# 节点属性实例表 11
class NodeAttrLivingModel(models.Model):
    desc = models.CharField(max_length=100,default='',verbose_name='内容值')
    nattr = models.ForeignKey(NodeAttrModel,on_delete=models.CASCADE,verbose_name='节点属性表外键(所属节点属性)')
    fnode = models.ForeignKey(FlowNodeModel, on_delete=models.CASCADE, verbose_name='流程节点表外键(所属流程节点)')

    class Meta:
        db_table = 'tb_naliving'
    def __str__(self):
        return self.desc


# 流程实例表 12 (用户发起的流程)
class FlowLivingModel(models.Model):
     user = models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name='用户表外键(所属用户)')
     flow = models.ForeignKey(FlowModel,on_delete=models.CASCADE,verbose_name='所属流程')
     s_time = models.CharField(max_length=100,default=datetime.now,verbose_name='用户创建流程时间')

     class Meta:
        db_table = 'tb_fliving'
     def __str__(self):
         return self.user_id


# 流程实例审批表 13
class FlowLivingShenModel(models.Model):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name='用户表外键(所属用户)')
    flowliv = models.ForeignKey(FlowLivingModel,on_delete=models.CASCADE,verbose_name='流程实例外键(所属流程实例)')
    fnode = models.ForeignKey(FlowNodeModel, on_delete=models.CASCADE, verbose_name='流程节点表外键(所属流程节点)')
    s_time = models.CharField(max_length=100,default=datetime.now,verbose_name='申请时间 审批时间')
    postil = models.CharField(max_length=100,default='',verbose_name='批注')
    approver = models.CharField(max_length=100,default='',verbose_name='审批人')
    department = models.ForeignKey(DepartmentModel, on_delete=models.CASCADE, verbose_name='所属部门')
    node_state = models.IntegerField(default=0,verbose_name='1 已申请 2通过 3拒绝')
    flow_state = models.IntegerField(default=0,verbose_name='1 待审批 2审批通过 3驳回')

    class Meta:
        db_table = 'tb_flshen'

    def __str__(self):
        return self.user_id


# 工资表 14
class SaralyModel(models.Model):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name='用户表外键(所属用户)')
    atten = models.CharField(max_length=100,default='',verbose_name='出勤')
    absent = models.CharField(max_length=100,default='',verbose_name='旷工')
    leave = models.CharField(max_length=100,default='',verbose_name='请假')
    base_pay = models.IntegerField(default='',verbose_name='基本工资')
    post_pay = models.IntegerField(default='',verbose_name='岗位工资')
    s_time = models.CharField(max_length=100,default=datetime.now,verbose_name='创建时间')

    class Meta:
        db_table = 'tb_saraly'
    def __str__(self):
        return self.base_pay

